<?php


define('NORMAL', "NORMAL");
define('RSS', "RSS");
define('BLOG', "BLOG");
define('LETTERS', "LETTERS");
define('SHORT_LETTERS', "SHORT_LETTERS");
define('STANDARD', "STANDARD");
define('STANDARD_PLUS', "STANDARD_PLUS");
define('EXTENDED', "EXTENDED");
define('EXTENDED_PLUS', "EXTENDED_PLUS");
define('TIME', 'TIME');
define('YEAR', 'YEAR');


Class tdw extends TagLibrary {

    function dummy(){}

    function upper2($name, $data, $pars) {
        
        echo "<b>name</b><p>{$name}";
        echo "<hr><b>data</b><p style=\"color: {$pars['color']};\">{$data}</p>";
        foreach($pars as $k => $v) {
            echo "<hr><b>{$k}</b><p>{$v}";
        }
        
        exit;
    }

    function upper($name, $data, $pars) {
        
        return strtoupper($data);
    }
    
    function formatdate($name, $data, $pars) {
		
        $date = $data;
        $format = $pars['format'];
        
        
   

		switch ($format) {
			case RSS:
				ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
				$result = date("D, j M Y 06:00:00 +0100",mktime(0, 0, 0, $token[2], $token[3], $token[1]));
				
			break;
			
			case LETTERS:

			ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
			$result = date("F jS Y",mktime(0, 0, 0, $token[2], $token[3], $token[1]));


			break;
			
			case SHORT_LETTERS:

			ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
			$result = date("M j, Y",mktime(0, 0, 0, $token[2], $token[3], $token[1]));


			break;

			case STANDARD:
				
			if ($date != "") {

				if (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
					$result = "{$token[3]}/{$token[2]}/{$token[1]}";
				} elseif (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
					$result = "{$token[3]}/{$token[2]}/{$token[1]}";
				}
			} else {
				$result = "";
			}

			break;
			case STANDARD_PLUS:
				
			if ($date != "") {

				ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
				
				if (date("Ymd") == "{$token[1]}{$token[2]}{$token[3]}") {
					$result = aux::lingual("Oggi", "Today", "Oy");
				} else {				
					$result = "{$token[3]}/{$token[2]}/{$token[1]}";
				}
				if ($token[4] != "") {
					$result .= " {$token[4]}:{$token[5]}";
				}
			} else {
				$result = "";
			}

			break;
			
			case BLOG:
				
			if ($date != "") {

				ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
				$date = date("jS M",mktime(0, 0, 0, $token[2], $token[3], $token[1]));
				
				$result = "<div title=\"Oggi\" style=\"float: left; line-height: 13px; font-size: 9px;padding-top: 4px; margin: 2px 20px 0px 10px; width: 29px; height: 32px; text-align:center; background: url(img/date.jpg) no-repeat;\">{$date}</div>";
			} else {
				$result = "";
			}

			break;
			
			case EXTENDED:
				
				
				if (isset($_SESSION['language'])) {
                                    setlocale(LC_ALL, aux::getLocale($_SESSION['language']));
                                } else {
                                    setlocale(LC_ALL,"ita_ita");
                                }
				if (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
					$day = "{$token[2]}/{$token[3]}/{$token[1]} {$token[4]}:{$token[5]}";

					$strtime = strtotime($day);
			
					$result = strftime("%A %d %B, %H:%M", $strtime); 
				} else if (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
					$day = "{$token[2]}/{$token[3]}/{$token[1]} 00:01";

					$strtime = strtotime($day);
			
					$result = strftime("%A %d %B", $strtime); 
				}
	
				
			break;
			
			case EXTENDED_PLUS:
				
				
				setlocale(LC_ALL, aux::getLocale($_SESSION['language']));		
				
				if (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {

					if ("{$token[2]}{$token[3]}{$token[1]}" == date("mdY")) {
						
						$result = "Oggi {$token[4]}:{$token[5]}";
						
					} else {
					
						$day = "{$token[2]}/{$token[3]}/{$token[1]} {$token[4]}:{$token[5]}";
						$strtime = strtotime($day);
						$result = strftime("%A %d %B, %H:%M", $strtime); 
					}
				} else if (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
					
					if ("{$token[2]}{$token[3]}{$token[1]}" == date("mdY")) {
						$result = "Oggi";
						
					} else {
						$day = "{$token[2]}/{$token[3]}/{$token[1]} 00:01";
						$strtime = strtotime($day);
						$result = strftime("%A %d %B", $strtime); 
					}
					
				}
	
				
			break;
			
			
			case TIME:
				
				$h = substr($date,8,2);
				$m = substr($date,10,2); 
				
				return "{$h}:{$m}";
				
			break;
			
			case YEAR:
				$y = substr($date,0,4);
				
				return $y;
				
				break;
			
                        case NORMAL:
			default:
                        
                        

			ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
			$result = "{$token[3]}.{$token[2]}.{$token[1]}";
			break;

		}

                #echo $result;exit;

		return $result;
			         
		
    }

}

?>